<template>
  <el-dialog
    title="题目审核"
    :visible="value"
    @close="closeDialog"
    width="30%"
    :rules="rules"
  >
    <el-form ref="formRef" :model="form" label-width="80px">
      <el-form-item label-width="1px">
        <el-radio-group v-model.number="form.chkState">
          <el-radio label="1">通过</el-radio>
          <el-radio label="2">拒绝</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label-width="1px" prop="chkRemarks">
        <el-input
          type="textarea"
          v-model="form.chkRemarks"
          placeholder="请输入审核意见"
        ></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button type="primary" @click="submitForm('ruleForm')"
        >确 定</el-button
      >
    </span>
    <el-alert title="警告提示的文案" type="warning" center show-icon v-if="condition">
    </el-alert>
  </el-dialog>
</template>

<script>
import { detail, choiceCheck } from '@/api/hmmm/questions.js'
export default {
  name: 'questionCheckDialog',
  props: {
    // 接受id
    id: {
      type: [Number, String],
      required: true
    },
    value: {
      type: [String, Boolean],
      required: true
    }
  },
  data () {
    var Remarks = (rule, value, callback) => {
      if (value === '') {
        this.condition = true
        callback(new Error('请输入密码'))
      } else {
        callback()
      }
    }
    return {
      questionDetail: {},
      form: {
        chkState: 0,
        chkRemarks: '',
        id: this.id
      },
      rules: {
        // resource: [
        //   { required: true, message: '请选择活动资源', trigger: 'change' }
        // ],
        chkRemarks: [
          { required: true, message: '请填写活动形式', trigger: 'blur' },
          { validator: Remarks, trigger: 'blur' }
        ]
      },
      condition: false
    }
  },
  created () {
    this.getDetail()
  },
  methods: {
    // 提交审核
    submitForm () {
      this.$refs.formRef.validate(async (valid) => {
        if (valid) {
          await choiceCheck(this.form)
          this.closeDialog()
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    // 打开弹出框函数
    closeDialog () {
      this.$emit('input', false)
    },
    // 获取题目详情
    async getDetail () {
      const res = await detail(this.id)
      this.questionDetail = res.data
      console.log(res.data)
      this.form.chkState = res.data.chkState
      this.form.chkRemarks = res.data.chkRemarks
    }
  }
}
</script>

<style scoped lang='less'></style>
<style>
.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}

.grid-content {
  border-radius: 4px;
  min-height: 15px;
}
::v-deep .el-checkbox-group .el-checkbox {
  display: block;
}
.dialog-footer {
  display: flex;
  justify-content: flex-end;
}
</style>
